package model;

import java.util.ArrayList;
import java.util.TreeSet;

import dataLayer.DAOAbsence;
import dataLayer.DAOGroup;
import dataLayer.DAOTeacher;

public class College {
	private static College instance = null;

	private TreeSet<Teacher> teacherList = new TreeSet<Teacher>();
	private TreeSet<Teacher> deletedTeacherList = new TreeSet<Teacher>();
	private TreeSet<Group> groupList = new TreeSet<Group>();
	private TreeSet<Absence> absenceListToday = new TreeSet<Absence>();
	private TreeSet<Absence> absenceListWeek = new TreeSet<Absence>();

	private ArrayList<Reason> reasonList = new ArrayList<Reason>();

	private College() {

		
		teacherList = DAOTeacher.getInstance().loadallactiveTeacher();
		deletedTeacherList = DAOTeacher.getInstance().loadalldeletedTeacher();
		groupList = DAOGroup.getInstance().loadallGroup();
		absenceListToday = DAOAbsence.getInstance().loadAllAbsenceToday();
		absenceListWeek = DAOAbsence.getInstance().loadAllAbsenceWeek();

	}

	// methods are boolean for if loop
	public boolean addGroup(Group g) {
		if (groupList.add(g)) {
			DAOGroup.getInstance();
			return true;
		}
		return false;
	}

	public boolean addTeacher(Teacher t) {
		if (teacherList.add(t)) {
			DAOTeacher.getInstance();
			return true;
		}

		return false;
	}

	public TreeSet<Group> getAllGroups() {
		return groupList;
	}

	public TreeSet<Teacher> getAllactiveTeachers() {
		return teacherList;
	}

	public TreeSet<Teacher> getAllDeletedTeachers() {
		return deletedTeacherList;
	}

	public ArrayList<Reason> getAllReasons() {

		return reasonList;
	}

	public TreeSet<Absence> getAbsenceListToday() {
		return absenceListToday;
	}

	public TreeSet<Absence> getAbsenceListWeek() {
		return absenceListWeek;
	}

	public void setAbsenceListToday() {
		absenceListToday = DAOAbsence.getInstance().loadAllAbsenceToday();
		
	}

	public void setAbsenceListWeek() {
		absenceListWeek = DAOAbsence.getInstance().loadAllAbsenceWeek();
	}

	public void setAllactiveTeachers() {
		teacherList = DAOTeacher.getInstance().loadallactiveTeacher();
	}

	public void setAlldeletedTeachers() {
		deletedTeacherList = DAOTeacher.getInstance().loadalldeletedTeacher();
	}

	public void setAllAbsences() {
		teacherList = DAOTeacher.getInstance().loadallactiveTeacher();
	}

	public void setAllGroups() {
		groupList = DAOGroup.getInstance().loadallGroup();
	}

	// Method to return the group_Id from each group in treeset
	public String getGroupId(String group) {
		for (Group g : groupList) {
			if (g.Group_Name.equalsIgnoreCase(group)) {
				return g.Group_Name;
			}
		}
		return null;
	}

	// Method to return a Group from the treeset
	public Group getGroup(Group g) {
		String name = g.getGroup_name();
		for (Group g1 : groupList) {
			if (g1.getGroup_name() == name) {
				return g1;
			}
		}
		return null;
	}

	// Method to return a Teacher from the treeset
	public Teacher getTeacher(Teacher t) {
		String id = t.getTeacher_code();
		for (Teacher t2 : teacherList) {
			if (t2.getTeacher_code() == id) {
				return t2;
			}
		}
		return null;
	}

	// Method to delete a Teacher from the treeset
	public void deleteTeacher(Teacher t) {
		String code = t.getTeacher_code();
		for (Teacher t2 : teacherList) {
			if (code == t2.getTeacher_code()) {
				teacherList.remove(t2);
				break;
			}
		}
	}

	// Method to delete a Group from the treeset
	public void deleteGroup(Group g) {
		String name = g.getGroup_name();
		for (Group g2 : groupList) {
			if (name == g2.getGroup_name()) {
				groupList.remove(g2);
				break;
			}
		}
	}

	public static College getInstance() {
		if (instance == null) {
			instance = new College();
		}
		return instance;

	}

	public void setTeacher(Teacher t1) {
		// TODO set teacher voor treeset

	}

	public void setGroup(Group g2) {

	}

}
